import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index')
      }
    ]
  },

  // dashboard
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: '工作台',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '工作台', icon: 'el-icon-gongzuotai' }
    }]
  },

  // 新建仓库
  // {
  //   path: '/details',
  //   redirect: '/basicInfo/cage/detalis',
  //   name: '新建仓库'
  // },

  // basicInfo
  {
    path: '/basicInfo',
    component: Layout,
    redirect: '/basicInfo/cage',
    name: '基础信息管理',
    meta: { title: '基础信息管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: '/cage',
        name: '仓库管理',
        component: () => import('@/views/basicInfo/cage/index'),
        meta: { title: '仓库管理', icon: 'el-icon-yuandianxiao' }
      },
      // 仓库管理-新建仓库
      {
        path: '/details',
        component: () => import('@/views/basicInfo/cage/newBank/newBank'),
        hidden: true
      },

      {
        path: '/area',
        name: '库区管理',
        component: () => import('@/views/basicInfo/area/index'),
        meta: { title: '库区管理', icon: 'el-icon-yuandianxiao' }
      },
      {
        path: '/points',
        name: '库位管理',
        component: () => import('@/views/basicInfo/points/index'),
        meta: { title: '库位管理', icon: 'el-icon-yuandianxiao' }
      },
      {
        path: '/points-views',
        name: '库位视图',
        component: () => import('@/views/basicInfo/points-views/index'),
        meta: { title: '库位视图', icon: 'el-icon-yuandianxiao' }
      },
      {
        path: '/goods',
        name: '货品管理',
        component: () => import('@/views/basicInfo/goods/index'),
        meta: { title: '货品管理', icon: 'el-icon-yuandianxiao' }
      },
      {
        path: '/goods-category',
        name: '货品类型管理',
        component: () => import('@/views/basicInfo/goods-category/index'),
        meta: { title: '货品类型管理', icon: 'el-icon-yuandianxiao' }
      }
    ]
  },

  // business
  {
    path: '/business',
    component: Layout,
    redirect: '/business/customer',
    name: '商务管理',
    meta: { title: '商务管理', icon: 'el-icon-shangwu' },
    children: [
      {
        path: '/customer',
        name: '货主管理',
        component: () => import('@/views/business/customer/index'),
        meta: { title: '货主管理', icon: 'el-icon-yuandianxiao' }
      },
      {
        path: '/transportation',
        name: '承运商管理',
        component: () => import('@/views/business/transportation/index'),
        meta: { title: '承运商管理', icon: 'el-icon-yuandianxiao' }
      }
    ]
  },

  // bank-manage
  {
    path: '/bank-manage',
    component: Layout,
    redirect: '/bank-manage/list',
    name: '库内管理',
    meta: { title: '库内管理', icon: 'el-icon-cangku' },
    children: [
      {
        path: '/list',
        name: '盘点单',
        component: () => import('@/views/bank-manage/list/index'),
        meta: { title: '盘点单', icon: 'el-icon-yuandianxiao' }
      },
      {
        path: '/task',
        name: '盘点任务',
        component: () => import('@/views/bank-manage/task/index'),
        meta: { title: '盘点任务', icon: 'el-icon-yuandianxiao' }
      },
      {
        path: '/profit',
        name: '库存损益',
        component: () => import('@/views/bank-manage/profit/index'),
        meta: { title: '库存损益', icon: 'el-icon-yuandianxiao' }
      },
      {
        path: '/in-time',
        name: '实时库存',
        component: () => import('@/views/bank-manage/in-time/index'),
        meta: { title: '实时库存', icon: 'el-icon-yuandianxiao' }
      }
    ]
  },

  // bankIn
  {
    path: '/bankIn',
    component: Layout,
    redirect: '/bankIn/inBankList',
    name: '入库管理',
    meta: { title: '入库管理', icon: 'el-icon-ruku-Warehousing' },
    children: [
      {
        path: '/inBankList',
        name: '入库单',
        component: () => import('@/views/bankIn/inBankList/index'),
        meta: { title: '盘点单', icon: 'el-icon-yuandianxiao' }
      },
      {
        path: '/receive',
        name: '收货任务',
        component: () => import('@/views/bankIn/receive/index'),
        meta: { title: '收货任务', icon: 'el-icon-yuandianxiao' }
      },
      {
        path: '/putaway',
        name: '上架任务',
        component: () => import('@/views/bankIn/putaway/index'),
        meta: { title: '上架任务', icon: 'el-icon-yuandianxiao' }
      }
    ]
  },

  // bankOut
  {
    path: '/bankOut',
    component: Layout,
    redirect: '/bankOut/inBankList',
    name: '出库管理',
    meta: { title: '出库管理', icon: 'el-icon-cangpeitubiao_chukuhuanhuochuku' },
    children: [
      {
        path: '/outBankList',
        name: '出库单',
        component: () => import('@/views/bankOut/outBankList/index'),
        meta: { title: '出库单', icon: 'el-icon-yuandianxiao' }
      },
      {
        path: '/pickup',
        name: '拣货任务',
        component: () => import('@/views/bankOut/pickup/index'),
        meta: { title: '拣货任务', icon: 'el-icon-yuandianxiao' }
      },
      {
        path: '/passaway',
        name: '交接任务',
        component: () => import('@/views/bankOut/passaway/index'),
        meta: { title: '交接任务', icon: 'el-icon-yuandianxiao' }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
